import { Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { Body, _HttpClient } from '@delon/theme';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { WarningDetailComponent } from '../warning-detail/warning-detail.component'
import { ApiService } from '@core/services/api';
import { STData } from '@delon/abc';
import { ACLService } from '@delon/acl';

@Component({
  selector: 'warning-list',
  templateUrl: './warning-list.component.html',
  styles: []
})
export class WarningListComponent implements OnInit {
  @ViewChild('st', { static: false }) st: TablePageComponent;
  detailFlag:boolean = this.aclService.canAbility("warning/detail");//检查用户按钮权限
  selectData: any[];
  loading = false;
  addUserInfo = {
    userAccount: '',
    userPassword: '',
    userName: '',
    roles: [],
    depts: []
  };
  config: SPage = {
    columns: [
      {
        index: 'id',
        title: '多选',
        type: ColumnType.checkbox,
      },
      {
        index: 'deviceId',
        title: '设备ID',
        filter: {
          placeholder: '请输入设备ID',
          type: 'string'
        }
      },
      {
        index: 'eventLevel',
        title: '事件等级'
      },
      {
        index: 'eventName',
        title: '事件'
      },
      {
        index: 'eventProduceTime',
        title: '发生时间'
      },
      {
        index: 'eventResponsePhone',
        title: '电话'
      },
      {
        index: 'eventDisposeStatus',
        title: '状态',
        type: ColumnType.tag,
        tag:{
          1:{text:'未响应',color:'red'},
          2:{text:'超时响应',color:'red'},
          3:{text:'未处理',color:'red'},
          4:{text:'超时处理',color:'red'},
          5:{text:'处理中',color:'red'},
          6:{text:'处理完成',color:'green'}
        }
      }
    ],
    showCheckBox: false,
    reqUrl:'/core/event/page',
    defaultParam:{order:'eventProduceTime desc'}
    // editBtn: [
    //   { title: '详情',iif:()=> this.detailFlag }
    // ]
  }
  constructor(private http: _HttpClient,  private api: ApiService, private modal: NzModalService, private message: NzMessageService,private aclService: ACLService) { }
  
  ngOnInit() {

  }


  // 编辑功能开始
  detail(type: 0 | 1 = 0, _param?: object): void {
    
    const title = '事件详情';
    const modal = this.modal.create({
      nzTitle: title,
      nzContent: WarningDetailComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
        _param
      },
      
      nzFooter: null
    })
  }

  operate(e: any): void {
    
    if(e.title === '详情'){
      this.detail(1, e.data);
    }
  }
  _console(e: any): void {
    this.selectData = e;
  }
  
}
